package com.neuedu.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.neuedu.dao.DeviceDao;
import com.neuedu.model.Device;

//把dao接口实现类，交给spring进行管理
@Repository
public class DeviceDaoImpl implements DeviceDao {

	//代码层级的整合spring+mybatis
	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;
	
	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlSessionTemplate = sqlSessionTemplate;
	}
	
	@Override
	public int countDevice() {
		return sqlSessionTemplate.getMapper(DeviceDao.class).countDevice();
	}

	@Override
	public List<Device> findAll(Map<String, Object> map) {
		return sqlSessionTemplate.getMapper(DeviceDao.class).findAll(map);
	}

	@Override
	public int addDevice(Device u) {
		return sqlSessionTemplate.getMapper(DeviceDao.class).addDevice(u);
	}

	@Override
	public int updateDevice(Device u) {
		return  sqlSessionTemplate.getMapper(DeviceDao.class).updateDevice(u);
	}

	@Override
	public int deleteDevice(int id) {
		return sqlSessionTemplate.getMapper(DeviceDao.class).deleteDevice(id);
	}

	@Override
	public Device findOne(int id) {
		// TODO Auto-generated method stub
		return sqlSessionTemplate.getMapper(DeviceDao.class).findOne(id);
	}

}
